package com.tiny.persistence.repository.impl;

import java.util.List;

import javax.persistence.Query;

import org.apache.log4j.Logger;

import com.tiny.persistence.domain.Qrcode;
import com.tiny.persistence.repository.plus.QrcodeRepoPlus;

public class QrcodeRepoImpl extends BaseRepoImpl<Qrcode> implements QrcodeRepoPlus{

    private static Logger logger = Logger.getLogger(QrcodeRepoImpl.class);

	public int getMaxId(String serialNumber) {
		String hql = "select id as maxId from Qrcode where serialNumber=:serialNumber";
		Query query = em.createQuery(hql);
		query.setParameter("serialNumber", serialNumber);
        @SuppressWarnings("unchecked")
		List<Integer> list = query.getResultList();
        logger.info("======= " + list);
        if(list != null && list.size() > 0){
        	return list.get(0);
        }
		hql = "select id as maxId from Qrcode order by id desc";
		query = em.createQuery(hql);
        @SuppressWarnings("unchecked")
		List<Integer> list2 = query.getResultList();
        logger.info("======= " + list2);
        if(list2 != null && list2.size() > 0){
        	return list2.get(0);
        }
        return 0;
	}


}
